package com.ruoyi.business.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.business.domain.bo.FilePersonAssessBo;
import com.ruoyi.business.domain.vo.FilePersonAssessVo;
import com.ruoyi.business.service.IFilePersonAssessService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;
import java.util.List;

/**
 * 人员考核
 *
 * @author sal
 * @date 2024-11-26
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/FilePersonAssess")
public class FilePersonAssessController extends BaseController {

    private final IFilePersonAssessService iFilePersonAssessService;


    @Log(title = "人员考核", businessType = BusinessType.IMPORT)
    @SaCheckPermission("business:FilePersonAssess:import")
    @PostMapping(value = "/importData", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public R<Void> importData(@RequestPart("file") MultipartFile file, boolean updateSupport) throws Exception {
        iFilePersonAssessService.importData(file);
        return R.ok();
    }
    /**
     * 查询人员考核列表
     */
    @SaCheckPermission("business:FilePersonAssess:list")
    @GetMapping("/list")
    public TableDataInfo<FilePersonAssessVo> list(FilePersonAssessBo bo, PageQuery pageQuery) {
        return iFilePersonAssessService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出人员考核列表
     */
    @SaCheckPermission("business:FilePersonAssess:export")
    @Log(title = "人员考核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(FilePersonAssessBo bo, HttpServletResponse response) {
        List<FilePersonAssessVo> list = iFilePersonAssessService.queryList(bo);
        ExcelUtil.exportExcel(list, "人员考核", FilePersonAssessVo.class, response);
    }

    /**
     * 获取人员考核详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("business:FilePersonAssess:query")
    @GetMapping("/{id}")
    public R<FilePersonAssessVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iFilePersonAssessService.queryById(id));
    }

    /**
     * 新增人员考核
     */
    @SaCheckPermission("business:FilePersonAssess:add")
    @Log(title = "人员考核", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody FilePersonAssessBo bo) {
        return toAjax(iFilePersonAssessService.insertByBo(bo));
    }

    /**
     * 修改人员考核
     */
    @SaCheckPermission("business:FilePersonAssess:edit")
    @Log(title = "人员考核", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody FilePersonAssessBo bo) {
        return toAjax(iFilePersonAssessService.updateByBo(bo));
    }

    /**
     * 删除人员考核
     *
     * @param ids 主键串
     */
    @SaCheckPermission("business:FilePersonAssess:remove")
    @Log(title = "人员考核", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iFilePersonAssessService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
